package br.com.lh.urabuilder.util
{
	import mx.validators.NumberValidator;
	import mx.validators.PhoneNumberValidator;
	import mx.validators.RegExpValidator;
	import mx.validators.StringValidator;
	import mx.validators.Validator;
	
	public class ValidatorFactory
	{
		public static var PHONE_VALIDATOR:String = "PHONE_VALIDATOR";
		public static var STRING_VALIDATOR:String = "STRING_VALIDATOR"; 
		public static var NUMBER_VALIDATOR:String = "NUMBER_VALIDATOR";
		
		public function ValidatorFactory(){
			
		}
		
		public static function getValidator(validatorType:String,
		maxLength:Number = Number.MAX_VALUE,required:Boolean = true):Validator{
			var resultValidator:Validator;
			if (validatorType == PHONE_VALIDATOR){
				resultValidator= new PhoneNumberValidator();
				resultValidator.required=required;
				return resultValidator;
			}else if (validatorType == STRING_VALIDATOR){
				resultValidator= new StringValidator();
				resultValidator.required=required;
				StringValidator(resultValidator).maxLength = maxLength;
				return resultValidator;
			}else if (validatorType == NUMBER_VALIDATOR){
				resultValidator= new NumberValidator();
				resultValidator.required = required;
				NumberValidator(resultValidator).maxValue = maxLength;
				return resultValidator;
			}
			return resultValidator;
		}
		
		public static function getRequiredValidator(validatorType:String,maxLength:Number):Validator{
			return getValidator(validatorType,maxLength,true);
		}
		
		public static function getUnlimitedRequiredStringValidator():Validator{
			return getValidator(STRING_VALIDATOR,Number.MAX_VALUE,true);
		}
		
		public static function getDefaultPhoneValidator():Validator{
			return getValidator(PHONE_VALIDATOR);
		}
		
		public static function getPatternValidator(regexp:String):Validator{
			var resultValidator:RegExpValidator =new RegExpValidator();
			resultValidator.expression = regexp;
			return resultValidator;
		}
		
	}
		
		
}